﻿using System.ComponentModel;
using SAPPDI.Entitys.Annotations;

namespace SAPPDI.Entitys
{
    public class Papel : INotifyPropertyChanged
    {
        private int _ID;
        
        public int Id
        {
            get { return this._ID; }
            set
            {
                this._ID = value;
                NotifyPropertyChanged("Id");
            }
        }

        private string _Nombre;
        
        public string Nombre
        {
            get { return _Nombre; }
            set
            {
                this._Nombre = value;
                NotifyPropertyChanged("Nombre");
            }
        }

        public Papel()
        {
        }

        public Papel(Papel elemento)
        {
            if (elemento == null) return;
            
            this._ID = elemento.Id;
            this._Nombre = elemento.Nombre;
        }

        public override string ToString()
        {
            return Nombre;
        }

        public override bool Equals(object obj)
        {
            if (obj==null || typeof(Papel) != obj.GetType())
                return false;
            var elemento = (Papel)obj;
            return this.Nombre == elemento.Nombre && this.Id == elemento.Id;
        }

        public static bool operator ==(Papel a, Papel b)
        {
            // If both are null, or both are same instance, return true.
            if (System.Object.ReferenceEquals(a, b))
            {
                return true;
            }

            // If one is null, but not both, return false.
            if (((object)a == null) || ((object)b == null))
            {
                return false;
            }

            // Return true if the fields match:
            return a.Nombre == b.Nombre && a.Id == b.Id;
        }

        public static bool operator !=(Papel a, Papel b)
        {
            return !(a == b);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void NotifyPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
